package com.zboin.controller;

import com.zboin.common.domain.AjaxResult;
import com.zboin.common.domain.PageResult;
import com.zboin.domain.Article;
import com.zboin.service.ArticleService;
import com.zboin.service.ArticleTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhboom
 * @date 2025/6/10 22:19
 */
@RestController
@RequestMapping("/article")
public class PortalController {

    private final ArticleService articleService;
    private final ArticleTypeService articleTypeService;

    public PortalController(ArticleService articleService, ArticleTypeService articleTypeService) {
        this.articleService = articleService;
        this.articleTypeService = articleTypeService;
    }

    @GetMapping("/content/{id}")
    public AjaxResult getArticleContent(@PathVariable("id") Integer id) {
        return articleService.getArticleContent(id);
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    public PageResult<Article> getFileList(Article article,
                                           @PathVariable("pageSize") Integer pageSize,
                                           @PathVariable("pageNum") Integer pageNum) {
        return articleService.list(pageNum, pageSize, article);
    }

    @GetMapping("/type/listAll")
    public AjaxResult getAllType() {
        return articleTypeService.getAllType();
    }

    @GetMapping("/listByType/{typeId}")
    public AjaxResult getArticleListByType(@PathVariable("typeId") Integer typeId) {
        return articleService.getArticleListByType(typeId);
    }
}
